﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Smart.Business.BodyFatCalculator
{
    public static class BodyFatCalculatorBL
    {
        public static double GetBMI(double height, double weight)
        {
            return weight / (height * height);
        }

        public static double GetBodyFat(double bmi, int age, bool isMale)
        {
            bool isAdult = false;
            if (age >= 18)
                isAdult = true;
            int sex = 0;
            if (isMale)
                sex = 1;

            double bodyFat = 0;
            if (isAdult)
                bodyFat = (1.2 * bmi) + (0.23 * age) - (10.8 * sex) - 5.4;
            else
                bodyFat = (1.51 * bmi) - (0.7 * age) - (3.6 * sex) + 1.4;
            return bodyFat;
        }

        public static string GetBMIValue(double bmi)
        {
            string value = "Not Defined";
            if (bmi <= 15.0)
                value = BMIValues.VERY_SEVERELY_UNDERWEIGHT;
            else if (bmi <= 16.0)
                value = BMIValues.SEVERELY_UNDERWEIGHT;
            else if (bmi <= 18.5)
                value = BMIValues.UNDERWEIGHT;
            else if (bmi <= 25.0)
                value = BMIValues.NORMAL;
            else if (bmi <= 30.0)
                value = BMIValues.OVERWEIGHT;
            else if (bmi <= 35.0)
                value = BMIValues.OBESE_CLASS_I;
            else if (bmi <= 40.0)
                value = BMIValues.OBESE_CLASS_II;
            else
                value = BMIValues.OBESE_CLASS_III;

            return value;
        }

        public static string GetBodyFatValue(double bodyFat, bool isMale)
        {
            string value = "Not Defined";
            if (isMale)
            {
                if (bodyFat < 2.0)
                    value = BodyFatValues.LACK_OF_ESSENTIAL_FAT;
                else if (bodyFat <= 5.0)
                    value = BodyFatValues.ESSENTIAL_FAT;
                else if (bodyFat <= 13.0)
                    value = BodyFatValues.ATHLETES;
                else if (bodyFat <= 17.0)
                    value = BodyFatValues.FITNESS;
                else if (bodyFat <= 24.0)
                    value = BodyFatValues.JUST_AVERAGE;
                else
                    value = BodyFatValues.EXCESS_FAT;
            }
            else
            {
                if (bodyFat < 10.0)
                    value = BodyFatValues.LACK_OF_ESSENTIAL_FAT;
                else if (bodyFat <= 13.0)
                    value = BodyFatValues.ESSENTIAL_FAT;
                else if (bodyFat <= 20.0)
                    value = BodyFatValues.ATHLETES;
                else if (bodyFat <= 24.0)
                    value = BodyFatValues.FITNESS;
                else if (bodyFat <= 31.0)
                    value = BodyFatValues.JUST_AVERAGE;
                else
                    value = BodyFatValues.EXCESS_FAT;
            }

            return value;
        }
    }

    public class BMIValues
    {
        public const string VERY_SEVERELY_UNDERWEIGHT = "Very severely underweight";
        public const string SEVERELY_UNDERWEIGHT = "Severely underweight";
        public const string UNDERWEIGHT = "Underweight";
        public const string NORMAL = "Normal (healthy weight)";
        public const string OVERWEIGHT = "Overweight";
        public const string OBESE_CLASS_I = "Obese Class I (Moderately obese)";
        public const string OBESE_CLASS_II = "Obese Class II (Severely obese)";
        public const string OBESE_CLASS_III = "Obese Class III (Very severely obese)";
    }

    public class BodyFatValues
    {
        public const string LACK_OF_ESSENTIAL_FAT = "Lack of essential fat";
        public const string ESSENTIAL_FAT = "Essential fat";
        public const string ATHLETES = "Athletes";
        public const string FITNESS = "Fitness";
        public const string JUST_AVERAGE = "Just Average";
        public const string EXCESS_FAT = "Excess Fat";
    }
}
